convert str[i] into integer type using stoi()